from sklearn.metrics import roc_curve, auc
from matplotlib import pyplot as plt
import basic_func.general_func as bf

def plot_auc(df,params):
    bf.zh_font(params)
    df.reset_index(inplace=True)
    fig, ax = plt.subplots()
    for i in range(len(df.columns)-1):
        fpr, tpr, thresholds = roc_curve(df[df.columns[0]],
                                         df[df.columns[i+1]])
        roc_auc = auc(fpr, tpr) # 计算auc值
        ax.plot(fpr, tpr,
                label=f'{df.columns[i+1]}(AUC = {roc_auc:2f})',
                lw = 2,
                color = bf.color_selector_1(params,2)[i])
    ax.legend(loc="lower right")
    ax.set_xlabel(params['x_label'],
                  fontsize = params['label_fontsize'])
    ax.set_ylabel(params['y_label'],
                  fontsize = params['label_fontsize'])
    ax.set_xlim([-0.05, 1.05])
    ax.set_ylim([-0.05, 1.05])
    ax.set_title(params['title'])
    plt.show()


    

if __name__ == '__main__':
    df,params = bf.read_data('test_data/AUC曲线绘制.xlsx')
    plot_auc(df,params)
